package a18_SimplePracticeAll;

import java.util.Random;

/**
 * @Author quan
 * @Description 对A6的优化进阶版：打乱数组
 * @Date 2023/2/3 10:54
 */
public class A61_GrabRedEnvelope {
    public static void main(String[] args) {
        //1、打乱奖池的顺序
        int[] arr = {2,588,888,1000,9999};
        Random r = new Random();
        for (int i = 0; i < arr.length; i++) {
            int randomIndex = r.nextInt(arr.length);
            //打乱数组：拿随机索引下的元素和数组的索引值i下的元素交换
            int temp = arr[i];
            arr[i] = arr[randomIndex];
            arr[randomIndex] = temp;
        }
        //2、从奖池中按索引拿出来
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
    }
}
